package com.siyu.rehearsal.grpc;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

public class TimeGenerator {

    public static ArrayList<String> generateFiveMinuteIntervals(LocalDateTime start, LocalDateTime end) {
        ArrayList<String> timeStamps = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

        LocalDateTime current = start;
        while (current.isBefore(end) || current.equals(end)) {
            String formattedTime;
            if (current.getHour() == 0 && current.getMinute() == 0) {
                // If it's midnight, adjust the date to the previous day
                LocalDateTime previousDay = current.minusDays(1).withHour(0).withMinute(0);
                formattedTime = previousDay.format(formatter).replace("00:00", "24:00");
            } else {
                formattedTime = current.format(formatter);
            }
            timeStamps.add(formattedTime);
            current = current.plus(Duration.ofMinutes(5));
        }

        return timeStamps;
    }

    public static ArrayList<String> chulimin(String beginTime,String endTime) {
        LocalDateTime start = LocalDateTime.parse(beginTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
        LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));

        ArrayList<String> timeStamps = generateFiveMinuteIntervals(start, end);
      return timeStamps;
    }
}